package com.winit.projectPlan.repository;

import com.winit.projectPlan.model.ProjectPlan;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public interface ProjectPlanRepository extends CrudRepository<ProjectPlan, String> {
    @Query(value = "SELECT mp.*, ma.* FROM matrix_project_plan mp " +
            " LEFT JOIN matrix_attachment ma ON mp.project_plan_id =ma.attachment_owner_id " +
            " WHERE 1 = 1 AND (ma.attachment_is_del IS NULL OR ma.attachment_is_del = '1')  " +
            " AND (?1 is null or mp.project_plan_id=?1) " +
            " AND (?7 is null or mp.project_plan_create_time >=?7) " +
            " AND (?2 IS NULL  OR mp.project_plan_status <> ?2) " +
            " AND (?3 IS NULL OR  mp.project_plan_is_del = ?3) " +
            " AND (?4 IS NULL OR (mp.project_plan_charger_account = ?4 OR mp.project_plan_creater_account = ?4)) " +
            " AND (?5 IS NULL OR mp.project_plan_online_time = ?5) " +
            " AND (?6 IS NULL OR (mp.project_plan_id = ?6 OR mp.project_plan_name = ?6 OR mp.project_plan_no = ?6 OR mp.project_plan_code = ?6 OR mp.project_plan_desc LIKE concat('%', ?6, '%'))) " +
            " ORDER BY mp.project_plan_create_time DESC ", nativeQuery = true)
    List<ProjectPlan> getProjectPlans(String projectPlanId, String status, String projectPlanIsDel, String userAccount, Date onlineTime, String keyword,String sDate);

    ProjectPlan findByProjectPlanIdAndProjectPlanIsDelNot(String projectPlanId, String projectPlanIsDel);

    List<ProjectPlan> findByProjectPlanName(String projectPlanName);

    ProjectPlan findByProjectPlanCode(String projectPlanCode);

    ProjectPlan findByUplanId(String uplanId);
}
